import request from './request'
import { AxiosPromise } from 'axios'

// 分页获取产品分类数据下拉列表
export function typePageSelect(data: object): AxiosPromise<GoodAPIResponse.TypeList> {
  return request({
    url: '/goods/select/typePageSelect',
    method: 'post',
    data,
  })
}

/**
 * 获取产品分类下拉选项
 */
export function getGoodsType(): AxiosPromise<GoodAPIResponse.GoodCategoryOptions> {
  return request({
    url: '/goods/select/getGoodsType',
    method: 'get',
  })
}

// 分页获取品牌数据下拉列表
export function brandPageSelect(data: object): AxiosPromise<GoodAPIResponse.BrandOptions> {
  return request({
    url: '/goods/select/pageSelect',
    method: 'post',
    data,
  })
}

// 分页获取单位下拉数据列表
export function unitPageSelect(data: object) {
  return request({
    url: '/goods/select/unitPageSelect',
    method: 'post',
    data,
  })
}

// 分页获取参数下拉数据列表
export function paramPageSelect(data: object) {
  return request({
    url: '/goods/select/paramPageSelect',
    method: 'post',
    data,
  })
}

// 分页获取规格下拉数据列表
export function specPageSelect(data: object) {
  return request({
    url: '/goods/select/specPageSelect',
    method: 'post',
    data,
  })
}

// 根据参数ID获取参数字段
export function getParamFields(paramId: string) {
  return request({
    url: '/goods/set/param/getParamFields/' + paramId,
    method: 'get',
  })
}

// 获取产品列表
export function getProductList(data: object) {
  return request({
    url: '/goods/product/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取商品列表
 * @param {GoodAPIRequest.GetGoodListParam} data - 请求参数
 * @param {string} data.brandId - 品牌ID
 * @param {Array<string>} data.goodsIdList - 商品，仅导出生效
 * @param {number} data.coreMaterials - 是否核心物料：0-否，1-是
 * @param {number} data.goodsType - 商品类型：1-成品，2-配件
 * @param {string} data.keyword - 关键词搜索：商品名称/型号/条码/规格名称
 * @param {number} data.limit - 每页显示数量
 * @param {number} data.page - 当面页码
 * @param {number} data.source - 产品来源：1-系统创建，2-excel导入，3-金蝶ERP，4-第三方接口创建，5-用友
 * @param {string} data.typeId - 商品一级分类ID
 * @param {string} data.typeThreeId - 商品三级分类ID
 * @param {string} data.typeTwoId - 商品二级分类ID
 * @param {string} data.unitId - 商品单位ID
 */
export function getGoods(
  data: GoodAPIRequest.GetGoodListParam,
): AxiosPromise<GoodAPIResponse.GoodList> {
  return request({
    url: '/goods/getGoodsList',
    method: 'post',
    data,
  })
}

// 批量启用或禁用产品
export function productDisable(data: object, status: any): AxiosPromise<APIResponse> {
  return request({
    url: '/goods/product/disable',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除产品
export function productDelete(data: object) {
  return request({
    url: '/goods/product/',
    method: 'delete',
    data,
  })
}

// 新增或修改产品
export function productSave(data: object) {
  return request({
    url: '/goods/product/save',
    method: 'post',
    data,
  })
}

// 根据产品ID获取产品修改前的信息
export function getInfo(id: string) {
  return request({
    url: '/goods/product/getInfo/' + id,
    method: 'get',
  })
}

// 根据产品ID获取产品详情
export function getProductDetail(id: string) {
  return request({
    url: '/goods/product/getProductDetail/' + id,
    method: 'get',
  })
}

// 根据产品ID获取产品说明书
export function getInsDetail(id: string) {
  return request({
    url: '/goods/product/getProductInstructionBook/' + id,
    method: 'get',
  })
}

// 根据产品ID获取产品视频
export function getVideoDetail(id: string) {
  return request({
    url: '/goods/product/getProductVideo/' + id,
    method: 'get',
  })
}

/**
 * 根据产品ID获取规格列表
 * @param data - 请求参数
 * @param {string} data.code - 规格SKU码，支持模糊查询
 * @param {number} data.limit - 每页显示数量
 * @param {string} data.name - 规格名称，支持模糊查询
 * @param {number} data.page - 当前页码
 * @param id - 商品id
 */
export function getProductSpec(
  data: GoodAPIRequest.GetGoodSpecParam,
  id: string,
): AxiosPromise<APIResponseList<ProductAPIResponse.ProductSpec>> {
  return request({
    url: '/goods/product/getSpecList/' + id,
    method: 'post',
    data,
  })
}

// 根据产品ID获取产品参数
export function getProductParam(id: string) {
  return request({
    url: '/goods/product/getProductParam/' + id,
    method: 'get',
  })
}

// 根据产品ID获取产品说明书列表
export function getInsList(data: object, id: string) {
  return request({
    url: '/goods/product/getPorductInstructionBookList/' + id,
    method: 'post',
    data,
  })
}

// 根据产品ID获取产品视频列表
export function getVideoList(data: object, id: string) {
  return request({
    url: '/goods/product/getProductVideoList/' + id,
    method: 'post',
    data,
  })
}

// 根据产品ID获取产品简介
export function getIntroduce(id: string) {
  return request({
    url: '/goods/product/getIntroduce/' + id,
    method: 'get',
  })
}

// 获取Boom关联的产品列表
export function getGoodsBoomList(data: object, id: string) {
  return request({
    url: '/goods/product/getGoodsBoomList/' + id,
    method: 'post',
    data,
  })
}

/**
 * 获取备件列表
 * @param data - 请求参数
 * @param data.page - 当前页码
 * @param data.limit - 每页显示数量
 * @param data.goodsIdList - 商品，仅导出生效
 * @param data.goodsType - 商品类型：1-成品，2-配件
 * @param data.brandId - 品牌ID
 * @param data.unitId - 商品单位ID
 * @param data.typeId - 商品一级分类ID
 * @param data.typeTwoId - 商品二级分类ID
 * @param data.typeThreeId - 商品三级分类ID
 * @param data.source - 产品来源：1-系统创建，2-excel导入，3-金蝶ERP，4-第三方接口创建，5-用友
 * @param data.keyword - 关键词搜索：商品名称/型号/编码/规格名称
 * @param data.coreMaterials - 是否核心物料：false-否，true-是
 * @param data.ascriptionType - 归属类型：1=商用，2-家用
 */
export function getSpareList(
  data: GoodAPIRequest.GetSparePartListParam,
): AxiosPromise<APIResponseList<GoodAPIResponse.SparePartListItem>> {
  return request({
    url: '/goods/spare/getList',
    method: 'post',
    data,
  })
}

// 新增或修改物料
export function spareSave(data: object) {
  return request({
    url: '/goods/spare/save',
    method: 'post',
    data,
  })
}

// 批量启用或禁用物料
export function SpareDisable(data: object, status: any) {
  return request({
    url: '/goods/spare/disable',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除物料
export function SpareDelete(data: object) {
  return request({
    url: '/goods/spare/',
    method: 'delete',
    data,
  })
}

// 根据物料ID获取产品修改前的信息
export function getSpareInfo(id: string) {
  return request({
    url: '/goods/spare/getInfo/' + id,
    method: 'get',
  })
}

// 根据物料ID获取物料详情
export function getSpareDetail(id: string) {
  return request({
    url: '/goods/spare/getDetail/' + id,
    method: 'get',
  })
}

/**
 * 根据产品ID获取规格列表
 * @param data - 请求参数
 * @param {string} data.code - 规格SKU码，支持模糊查询
 * @param {number} data.limit - 每页显示数量
 * @param {string} data.name - 规格名称，支持模糊查询
 * @param {number} data.page - 当前页码
 * @param id - 商品id
 */
export function getSpareSpec(
  data: GoodAPIRequest.GetGoodSpecParam,
  id: string,
): AxiosPromise<APIResponseList<ProductAPIResponse.ProductSpec>> {
  return request({
    url: '/goods/spare/getSpecList/' + id,
    method: 'post',
    data,
  })
}

// 根据物料ID获取参数列表
export function getSparePara(id: string) {
  return request({
    url: '/goods/spare/getSpareParam/' + id,
    method: 'get',
  })
}

// 根据物料ID获取物料简介
export function getSpareIntroduce(id: string) {
  return request({
    url: '/goods/spare/getIntroduce/' + id,
    method: 'get',
  })
}

// 获取Boom关联的产品列表
export function getSpareBoomList(data: object) {
  return request({
    url: '/goods/spare/getGoodsBoomList',
    method: 'post',
    data,
  })
}

// 获取Boom关联的产品列表
export function saveGoodsBoom(data: object): AxiosPromise<APIResponse> {
  return request({
    url: '/goods/product/saveGoodsBoom',
    method: 'post',
    data,
  })
}

// 根据产品ID获取产品Boom清单
export function getProductBoom(id: string) {
  return request({
    url: '/goods/product/getBoom/' + id,
    method: 'get',
  })
}

// 根据产品Boom ID获取产品Boom详情
export function getProductBoomDetail(id: string) {
  return request({
    url: '/goods/product/getProductBoom/' + id,
    method: 'get',
  })
}

// 根据产品Boom ID获取产品Boom子件列表
export function getProductBoomChildList(data: object, id: string) {
  return request({
    url: '/goods/product/getProductBoomChildList/' + id,
    method: 'post',
    data,
  })
}

/**
 * 获取产品列表（不包含规格，只包含产品信息）
 * @param {GoodAPIRequest.GetNotSpecGoodList} data - 请求参数
 */
export const getNotSpecGoodList = (
  data: GoodAPIRequest.GetNotSpecGoodList,
): AxiosPromise<GoodAPIResponse.NotSpecGoodList> => {
  return request({
    url: '/goods/getGoods',
    method: 'post',
    data,
  })
}

/**
 * 根据视频id获取产品列表
 * @param {String} id - 视频id
 */
export const getGoodListByVideoId = (
  id: string,
): AxiosPromise<GoodAPIResponse.GoodListByVideoId> => {
  return request({
    url: `/knowledge/video/getVideoRelationGoods/${id}`,
    method: 'get',
  })
}

/**
 * 根据说明书id获取产品列表
 * @param {String} id - 说明书id
 */
export const getGoodListByManualId = (id: string) => {
  return request({
    url: `/knowledge/instruction-book/getInstructionBookRelationGoods/${id}`,
    method: 'get',
  })
}

/**
 * 批量修改产品关联模块
 * @param data - 请求参数
 */
export const connectServiceModality = (
  data: GoodAPIRequest.ConnectServiceModality,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/goods/product/updateProductModule',
    method: 'post',
    data,
  })
}

/**
 * 获取物料BOM清单
 * @param id - 物料id
 */
export const getSpareBoomListBySpareId = (
  id: string,
): AxiosPromise<GoodAPIResponse.SpareBomList> => {
  return request({
    url: `/goods/spare/getBoom/${id}`,
    method: 'get',
  })
}

/**
 * 根据工单ID获取商品质保时间
 * @param {String} orderId - 工单id
 */
export const getGoodWarrantyInfoByOrderId = (
  orderId: string,
): AxiosPromise<GoodAPIResponse.OrderGoodWarrantyInfoList> => {
  return request({
    url: `/work/order/getOrderGoodsWarranty/${orderId}`,
    method: 'get',
  })
}

/**
 * 批量设置产品的移动端显示状态
 * @param visible - 移动端显示状态
 * @param codes - 产品编号列表
 */
export const setGoodListMobileVisible = (
  visible: 1 | 0,
  codes: Array<string>,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/goods/mobile/visible/${visible}`,
    method: 'post',
    data: {
      codes,
    },
  })
}

/**
 * 根据产品ID获取产品Boom子件列表
 * @param goodId 商品id
 */
export const getGoodBomChildListByGoodId = (
  goodId: string,
  data: { limit: number; page: number },
): AxiosPromise<APIResponseList<GoodAPIResponse.GoodBomChildListItem>> => {
  return request({
    url: `/goods/product/getBoomChildListByProductId/${goodId}`,
    method: 'post',
    data,
  })
}
